home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / AmigaOS / Aplus_Dev / AP-Website / download / pgp / pgp5gui-174b.lha / PGP5GUI-Src.lha / PGP5GUI-Src / PGPEInterface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-23  |  6.1 KB  |  283 lines

  1. /*
  2. ** PGP5GUI - A GUI using Magic User Interface v3.8
  3. **
  4. ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
  5. **
  6. ** This source code is released as FREEWARE - Use it for whatever you like,
  7. ** as long as NO financial reward is gained by you for such usage.
  8. **
  9. ** If you use any parts of the this source code for anything, give ME credit
  10. ** wherever credit is due, please ;-)
  11. */
  12.  
  13. /*
  14. ** Functions to handle the interface between PGPE and the GUI
  15. */
  16.  
  17. /* Library stuff */
  18. #include <libraries/mui.h>
  19. #include <dos/dostags.h>
  20.  
  21. /* Prototypes */
  22. #ifdef __GNUC__
  23. #include <clib/muimaster_protos.h>
  24. #include <proto/alib.h>
  25. #endif
  26.  
  27. #include <proto/muimaster.h>
  28. #include <proto/exec.h>
  29. #include <clib/alib_protos.h>
  30. #include <clib/alib_stdio_protos.h>
  31. #include <proto/dos.h>
  32.  
  33. /*  Ansi  */
  34. #include <string.h>
  35.  
  36. /* Include generated by GenCodeC */
  37. #include "PGP5GUI.h"
  38.  
  39. char *pgp5_tmp = "T:pgp5.tmp";
  40. char *pgp5_tmp_asc = "T:pgp5.tmp.asc";
  41.  
  42. char *armor_on_str = "+armor=on";
  43. char *armor_off_str = "+armor=off";
  44.  
  45. char *txmode_on_str = " +textmode=on";
  46. char *txmode_off_str = " +textmode=off";
  47.  
  48. extern char *enc_mode, *enc_options, *enc_files;
  49. extern char *encclippath, *encclipfile, *encclipfilename;
  50. extern char *exec_buff;
  51.  
  52. extern char *keyidsbuff;
  53. extern char *keyselection[];
  54.  
  55. extern int SelectPGPKey(struct ObjApp *app, char *sel[], char *title, ULONG multiselect);
  56. extern BOOL GetSaveASLFileName(struct ObjApp *app, char *hail, char *pathbuff, char *filebuff, char *tofile);
  57.  
  58. extern void PGP5_Execute(UBYTE *command, struct ObjApp *app);
  59. extern LONG GetCycle(Object *obj);
  60.  
  61. extern BOOL ReadClipToFile(char *tmp, struct ObjApp *app);
  62. extern BOOL WriteFileToClip(char *tmp, struct ObjApp *app);
  63.  
  64. /*
  65. ** Do the Encryption
  66. **         PGPE -r <recipient> [-s [-u <myid>]] [-aftz] [-o <outfile>] file ...
  67. **         PGPE -c [-aftz] [-o outfile] file ...
  68. */
  69. BOOL
  70. Do_Encryption(struct ObjApp *App)
  71. {
  72.     char tofile[512];
  73.  
  74.     /* Title for the file requester */
  75.     char title[] = "Save Encrypted Clip To (.asc) Text File...";
  76.  
  77.     char *encfilesbuff = "\0";
  78.  
  79.     int err = 0, i;
  80.  
  81.     /* Values for the Cycle gadgets on the Encryption page */
  82.     LONG Enc_MODE, Enc_USEARMOR, Enc_TEXTMODE, clipmode;
  83.  
  84.     clipmode = GetCycle(App->CY_Encrypt_CLIP);
  85.  
  86.     *encclipfilename = '\0';
  87.  
  88.     switch (clipmode)
  89.     {
  90.         case 3:        /* Encrypt from clip to clip */
  91.             if (ReadClipToFile(pgp5_tmp, App))
  92.             {
  93.                 encfilesbuff = pgp5_tmp;
  94.             }
  95.  
  96.             break;
  97.  
  98.         case 2:        /* Encrypt from clip to file */
  99.             if (ReadClipToFile(pgp5_tmp, App))
  100.             {
  101.                 encfilesbuff = pgp5_tmp;
  102.  
  103.                 /* Get name of file to save encrypted clip to... */
  104.                 if (GetSaveASLFileName(App, title, encclippath, encclipfile, tofile))
  105.                 {
  106.                     /* Build up the command line to send to DOS */
  107.                     sprintf(encclipfilename, " +force -o \"%s\"", tofile);
  108.                 }
  109.                 else
  110.                 {
  111.                     /* Force exit */
  112.                     encfilesbuff = "\0";
  113.                 }
  114.             }
  115.  
  116.             break;
  117.  
  118.         case 1:        /* Encrypt from file to clip */
  119.             get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&encfilesbuff);
  120.  
  121.             /* If we have a file name, then do the encryption */
  122.             if (*encfilesbuff)
  123.             {
  124.                 if (WriteFileToClip(encfilesbuff, App))
  125.                 {
  126.                     if (ReadClipToFile(pgp5_tmp, App))
  127.                     {
  128.                         encfilesbuff = pgp5_tmp;
  129.                     }
  130.                     else
  131.                     {
  132.                         /* Force exit */
  133.                         encfilesbuff = "\0";
  134.                     }
  135.                 }
  136.                 else
  137.                 {
  138.                     /* Force exit */
  139.                     encfilesbuff = "\0";
  140.                 }
  141.             }
  142.  
  143.             break;
  144.  
  145.         default:    /* Encrypt from file to default (file) */
  146.             get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&encfilesbuff);
  147.             break;
  148.     }
  149.  
  150.     /* If we have a file name, then do the encryption */
  151.     if (*encfilesbuff)
  152.     {
  153.         strcpy(enc_files, encfilesbuff);
  154.  
  155.         /* Get mode of encryption */
  156.         Enc_MODE = GetCycle(App->CY_Encrypt_MODE);
  157.  
  158.         /* Using clipboard? */
  159.         if (clipmode)
  160.         {
  161.             /* We lock these modes for clipboard use! */
  162.             Enc_USEARMOR = TRUE;
  163.             Enc_TEXTMODE = TRUE;
  164.         }
  165.         else
  166.         {
  167.             /* Get the values of the cycle gadgets */
  168.             Enc_USEARMOR = GetCycle(App->CY_Encrypt_USEARMOR);
  169.             Enc_TEXTMODE = GetCycle(App->CY_Encrypt_TEXTMODE);
  170.         }
  171.  
  172.         if (Enc_USEARMOR)
  173.         {
  174.             /* Use ASCII armor */
  175.             strcpy(enc_options, armor_on_str);
  176.         }
  177.         else
  178.         {
  179.             /* Don't use ASCII armor */
  180.             strcpy(enc_options, armor_off_str);
  181.         }
  182.  
  183.         if (Enc_TEXTMODE)
  184.         {
  185.             /* Do universal compatible text mode */
  186.             strcat(enc_options, txmode_on_str);
  187.         }
  188.         else
  189.         {
  190.             /* Don't do universal compatible text mode */
  191.             strcat(enc_options, txmode_off_str);
  192.         }
  193.  
  194.         /* Specify public-key encryption */
  195.         *enc_mode = '\0';
  196.  
  197.         switch (Enc_MODE)
  198.         {
  199.             case 2:
  200.                 /* Specify conventional encryption */
  201.                 strcpy(enc_mode,"-c");
  202.                 *keyidsbuff = '\0';
  203.                 break;
  204.  
  205.             case 1:
  206.                 /* Specify public-key encryption and signing */
  207.                 strcpy(enc_mode,"-s");
  208.  
  209.                 /* FALL-THROUGH */
  210.  
  211.             case 0:
  212.                 /* Get list of recipients */
  213.                 err = SelectPGPKey(App, keyselection, "Select Recipient(s)...",
  214.                                     MUIV_Listview_MultiSelect_Default);
  215.  
  216.                 if (!err)
  217.                 {
  218.                     if (*keyselection[0])
  219.                     {
  220.                         strcpy(keyidsbuff, "-r ");
  221.                         strcat(keyidsbuff, keyselection[0]);
  222.  
  223.                         for(i = 1; i < 256; i++)
  224.                         {
  225.                             if (*keyselection[i] != NULL)
  226.                             {
  227.                                 strcat(keyidsbuff, " -r ");
  228.                                 strcat(keyidsbuff, keyselection[i]);
  229.                             }
  230.                             else
  231.                             {
  232.                                 break;
  233.                             }
  234.                         }
  235.                     }
  236.                 }
  237.  
  238.                 break;
  239.  
  240.             default:
  241.                 break;
  242.         }
  243.  
  244.         if (!err)
  245.         {
  246.             /* Build up the command line to send to DOS */
  247.             sprintf(exec_buff, "PGPE %s %s %s %s \"%s\"",
  248.                     keyidsbuff, enc_mode, enc_options, encclipfilename, enc_files);
  249.  
  250.             /* Send the command to DOS */
  251.             PGP5_Execute(exec_buff, App);
  252.  
  253.             /* Are we using the clipboard? */
  254.             if (clipmode)
  255.             {
  256.                 /* clipmode not equal to 'clip to file'? */
  257.                 if (clipmode != 2)
  258.                 {
  259.                     /*
  260.                     ** Encrypt from file/clip to clip...
  261.                     ** Copy encrypted temporary file (T:pgp5.tmp.asc) to clip
  262.                     */
  263.                     WriteFileToClip(pgp5_tmp_asc, App);
  264.                 }
  265.  
  266.                 /*
  267.                 ** Encrypt from file/clip to clip...
  268.                 ** Delete encrypted temporary file (T:pgp5.tmp.asc, etc.)
  269.                 */
  270.                 DeleteFile(pgp5_tmp_asc);
  271.                 DeleteFile(pgp5_tmp);
  272.             }
  273.         }
  274.         else
  275.         {
  276.             if (err != -1)
  277.                 return(FALSE);    /* Couldn't get MUI App opened */
  278.         }
  279.     }
  280.  
  281.     return(TRUE);
  282. }
  283.